<template>
  <div class="enterprise-manage">
    <div class="btn-container">
      <el-button type="primary" @click="handleAdd">新增企业</el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      fit
      border
      style="width: 100%"
    >
      <el-table-column label="企业名称" prop="company_name" align="center" min-width="100px;" />
      <el-table-column label="企业logo" prop="info" align="center" min-width="100px;">
        <template slot-scope="{row}">
          <img :src="row.logo_img" />
        </template>
      </el-table-column>
      <el-table-column label="在线客服" prop="customer_service_qq" align="center" min-width="100px;" />
      <el-table-column label="主网址" prop="url" align="center" min-width="100px;" />
      <el-table-column label="备用网址" prop="standbyurl" align="center" min-width="100px;" />
      <el-table-column label="企业简介" prop="introduction" align="center" min-width="300px;" />
      <el-table-column label="自助认证(元)" prop="money" align="center" min-width="130px;" />
      <el-table-column label="自助担保(元)" prop="money" align="center" min-width="130px;" />
      <el-table-column label="操作" align="center" min-width="300px;">
        <template slot-scope="{row}">
          <span v-if="row.is_certification === 1"></span>
          <el-button v-else type="primary" @click="certification(row)">申请自助认证</el-button>
          <span v-if="row.is_guarantee === 1"></span>
          <el-button v-else type="primary" @click="guarantee(row)">申请自助担保</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog title="新增企业" :visible.sync="visible" class="enterprise-dialog">
      <el-form :model="formData" :rules="rules" label-width="100px" label-position="left">
        <el-form-item label="企业名称">
          <el-input v-model="formData.company_name" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="企业logo">
          <el-upload
            ref="upload"
            action="aaa"
            :auto-upload="false"
            :limit="1">
            <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item label="主网址">
          <el-input v-model="formData.url" placeholder="请输入主网址" />
        </el-form-item>
        <el-form-item label="在线客服">
          <el-input v-model="formData.customer_service_qq" placeholder="请输入在线客服qq" />
        </el-form-item>
        <el-form-item label="备用网址">
          <el-input type="textarea" rows="4" v-model="formData.standbyurl" placeholder="输入多个时请用英文逗号分割" />
        </el-form-item>
        <el-form-item label="企业简介">
          <el-input type="textarea" rows="4" v-model="formData.introduction" placeholder="请输入企业简介" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">
          取消
        </el-button>
        <el-button type="primary" @click="save()">
          确定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getEnterpriseList } from '../../../request/api';

export default {
  name: 'EnterpriseManage',
  data() {
    return {
      listLoading: false,
      list: [],
      visible: false,
      formData: {
        company_name: '',
        logo: '',
        url: '',
        customer_service_qq: '',
        standbyurl: '',
        introduction: ''
      },
      rules: {},
      logoList: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      getEnterpriseList().then(data => {
        this.list = data;
      })
    },
    certification(row) {},
    guarantee(row) {},
    handleAdd() {
      this.visible = true;
    },
    handleRemove() {},
    save() {
      const fileList = this.$refs.upload.$data.uploadFiles;
      if (!fileList.length) {
        this.$notify({
          type: 'warning',
          title: '提示',
          message: '请选择logo',
          duration: 2000
        });
        return;
      }
      this.formData.logo = fileList[0].raw;
    },
  }
}
</script>

<style lang="less">
  .enterprise-manage {
    padding: 0 10px 10px 10px;
    .btn-container {
      margin-bottom: 10px;
    }
  }
</style>
